<template>
    <div class="wrap">
        <div>{{detail.title}}</div>
        {{detail.state}}
        <shelf-btn :id="detail.id" :state="detail.state"></shelf-btn>
    </div>
</template>

<script>
import shelfBtn from '../components/shelfBtn'
export default {
    components:{
        shelfBtn
    },
    data(){
        return {
            detail:{}
        }
    },
    created(){
        let id = this.$route.params.id;
        let addList = JSON.parse(localStorage.getItem('addList')) || [];
        this.$http.get('/api/detail',{params:{id:id}}).then(res => {
            console.log(res);
            if(res.data.code === 1){
                let data =  res.data.data;
                addList.forEach(item => {
                    if(item.id === data.id){
                        data.state = true;
                    }
                })
                this.detail = data;
            }
        }).catch(error => {
            console.warn(error)
        })
    }
}
</script>
